# from django.contrib.auth import get_user_model
# from rest_framework import mixins, authentication, permissions, status
# from rest_framework.mixins import CreateModelMixin
# from rest_framework.response import Response
# from rest_framework_jwt.authentication import JSONWebTokenAuthentication
# from rest_framework_jwt.serializers import jwt_encode_handler, jwt_payload_handler
#
# User = get_user_model()
#
#
# class UserViewset(CreateModelMixin, mixins.UpdateModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
#     """
#     用户
#     """
#     serializer_class = UserRegSerializer
#     queryset = User.objects.all()
#     authentication_classes = (JSONWebTokenAuthentication, authentication.SessionAuthentication)
#
#     # permission_classes = (permissions.IsAuthenticated, )
#     def get_permissions(self):
#         if self.action == "retrieve":
#             return [permissions.IsAuthenticated()]
#         elif self.action == "create":
#             return []
#
#         return []
#
#     def create(self, request, *args, **kwargs):
#         serializer = self.get_serializer(data=request.data)
#         serializer.is_valid(raise_exception=True)
#         user = self.perform_create(serializer)
#
#         re_dict = serializer.data
#         payload = jwt_payload_handler(user)
#         re_dict["token"] = jwt_encode_handler(payload)
#         re_dict["name"] = user.name if user.name else user.username
#
#         headers = self.get_success_headers(serializer.data)
#         return Response(re_dict, status=status.HTTP_201_CREATED, headers=headers)
#
#     def get_object(self):
#         return self.request.user
#
#     def perform_create(self, serializer):
#         return serializer.save()